package splug.cjk;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CarPoolTab2Write extends Thread{

	private InputStream is;
	private OutputStream os;
	private String id;
	private String title;
	private String start;
	private String finish;
	private String time;
	private String content;
	private String date;
	private double latitude;
	private double longitude;

	public CarPoolTab2Write(InputStream is, OutputStream os, String id,
			String title, String start, String finish, String time,
			String content, String date, double latitude, double longitude) {
		
		this.is = is;
		this.os = os;
		this.id = id;
		this.title = title;
		this.start = start;
		this.finish = finish;
		this.time = time;
		this.content = content;
		this.date = date;
		this.latitude = latitude;
		this.longitude = longitude;
	}


	@Override
	public void run() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/carpool?useUnicode=true&characterEncoding=euckr","root","apmsetup");
			Statement stmt = conn.createStatement();
			
			String query = "INSERT INTO `carpool`.`bbscarpooltab2` (`title` ,`id` ,`start` ,`finish`, `time`, `content`, `date`, `latitude`, `longitude`) " +
					"VALUES ('" + title + "','" + id + "','" + start + "','" + finish + "','" + time + "','" + content + "','" + date + "','" + latitude + "','" + longitude +"');";
			
			stmt.execute("SET CHARACTER SET euckr");
			stmt.execute("set names euckr");

			stmt.executeUpdate(query);
			
			System.out.println("BBSCarPoolTab2 Write Complete!");
			
			OutputStreamWriter osw = new OutputStreamWriter(os);
			osw.write('1');
			osw.flush();
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}
}
